/**
 * 
 */
package com.ph.product.api.controller;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.dubbo.config.annotation.Reference;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.ph.base.BaseController;
import com.ph.shopping.common.core.constant.CommonConstants;
import com.ph.shopping.common.core.customenum.ResultEnum;
import com.ph.shopping.common.core.customenum.RoleEnum;
import com.ph.shopping.common.util.page.PageBean;
import com.ph.shopping.common.util.result.Result;
import com.ph.shopping.facade.permission.vo.SessionRoleVo;
import com.ph.shopping.facade.permission.vo.SessionUserVo;
import com.ph.shopping.facade.product.entity.PhProduct;
import com.ph.shopping.facade.product.entity.PhProductImage;
import com.ph.shopping.facade.product.entity.PhProductPropertyVal;
import com.ph.shopping.facade.product.service.IPhProductClassifyService;
import com.ph.shopping.facade.product.service.IProductPropertyService;
import com.ph.shopping.facade.product.service.IProductService;
import com.ph.shopping.facade.product.vo.PhProductClassifyVo;
import com.ph.shopping.facade.product.vo.PhProductPropertyVo;
import com.ph.shopping.facade.product.vo.PhProductVo;
import com.ph.shopping.facade.supplier.entity.Supplier;
import com.ph.shopping.facade.supplier.service.ISupplierService;
import com.ph.shopping.facade.supplier.vo.SupplierVo;

/**
 * @项目：phshopping-facade-
 *
 * 						@描述：
 *
 * 						@作者： yyg
 *
 * @创建时间：2017年3月14日 下午1:14:28
 *
 * @Copyright by yyg
 */

@Controller
@RequestMapping("/api/product")
public class ProductController extends BaseController {

	@Reference(version = "1.0.0")
	private IProductService iProductService;

	@Reference(version = "1.0.0")
	private IPhProductClassifyService iPhProductClassifyService;

	@Reference(version = "1.0.0")
	private IProductPropertyService iProductPropertyService;

	@Reference(version = "1.0.0")
	private ISupplierService iSupplierService;

	/**
	 * 商品添加页面跳转
	 * 
	 * @return
	 * @throws Exception
	 *
	 */
	@RequestMapping(value = "/toAddProductPage")
	public String toAddProduct(HttpServletRequest request, Model model) throws Exception {
		//获取当前登录用户
		SessionUserVo info = getLoginUser(request);
		SessionRoleVo role=info.getSessionRoleVo().get(0);
		PhProductClassifyVo phProductClassifyVo = new PhProductClassifyVo();
		// 查询分类级别为一级的数据
		phProductClassifyVo.setClassifyLevel(1);
		phProductClassifyVo.setDeleteFlag(1);
		List<PhProductClassifyVo> list = this.iPhProductClassifyService.getProductClassifyVoDetail(phProductClassifyVo);
		// 查询分类级别为二级的数据
		PhProductClassifyVo phProductClassifyVo2 = new PhProductClassifyVo();
		phProductClassifyVo2.setClassifyLevel(2);
		phProductClassifyVo2.setDeleteFlag(1);
		List<PhProductClassifyVo> list2 = this.iPhProductClassifyService
				.getProductClassifyVoDetail(phProductClassifyVo2);
		model.addAttribute("list", list);
		model.addAttribute("list2", list2);
		// 查询供应商数据
		// 供应商
		Supplier supplier = new Supplier();
		if(role.getRoleCode().equals(RoleEnum.ADMIN.getCode())){
			supplier.setSupplierType(CommonConstants.SUPPLIER_TYPE_TOTAL);
		}
			
		if(role.getRoleCode().equals(RoleEnum.CITY_AGENT.getCode())){
			supplier.setCreateId(info.getId());
		}
		supplier.setStatus(1);
		List<SupplierVo> supplierList = iSupplierService.getSupplierVoList(supplier);
		model.addAttribute("supplierList", supplierList);
		// 为供应商列表添加商品时，获取参数（供应商ID）
		String supplierId = request.getParameter("supplierId");
		if (StringUtils.isNotBlank(supplierId)) {
			model.addAttribute("supplierId", supplierId);
		} else {
			model.addAttribute("supplierId", "");
		}
		return "/product/products/addProduct";
	}

	@RequestMapping(value = "/getClassifiesForThreeId")
	@ResponseBody
	public Result toGetClassifyTree(@RequestParam("fid") Long fid, @RequestParam("sid") Long sid,
			@RequestParam("tid") Long tid) throws Exception {
		Result result = new Result();

		PhProductPropertyVo first = new PhProductPropertyVo();
		first.setClassifyId(fid);
		List<PhProductPropertyVo> list1 = this.iProductPropertyService.getPhProductPropertyVoList(first);
		PhProductPropertyVo second = new PhProductPropertyVo();
		second.setClassifyId(sid);
		List<PhProductPropertyVo> list2 = this.iProductPropertyService.getPhProductPropertyVoList(second);
		PhProductPropertyVo three = new PhProductPropertyVo();
		three.setClassifyId(tid);
		List<PhProductPropertyVo> list3 = this.iProductPropertyService.getPhProductPropertyVoList(three);

		List<PhProductPropertyVo> maps = new ArrayList<>();
		maps.addAll(list1);
		maps.addAll(list2);
		maps.addAll(list3);
		result.setData(maps);
		return result;
	}

	/**
	 * 商品添加
	 * 
	 * @description:
	 * @param productStr
	 * @param imageStr
	 * @param prpoValStr
	 * @return
	 * @author yyg
	 * @date 2017年3月15日
	 */
	@RequestMapping(value = "/add", method = RequestMethod.POST)
	@ResponseBody
	public Result addProduct(@ModelAttribute PhProduct phProduct, @RequestParam String imageJSON,
			@RequestParam String productPropertyValJSON, HttpServletRequest request) {
		// 获取当前的用户
		SessionUserVo info = getLoginUser(request);
		phProduct.setNumberOfPackages(phProduct.getNumberOfPackages() == null ? 0 : phProduct.getNumberOfPackages());
		phProduct.setSaleNoSaleStatus(2);
		phProduct.setCreateUser(info.getId());// 创建人
		// 获取用户角色区分是全国商品，还是本地商品；
		SessionRoleVo role = info.getSessionRoleVo().get(0);
		byte typeId = role.getRoleCode();
		if (typeId == RoleEnum.ADMIN.getCode()) { // 全国商品
			phProduct.setProductType(1);
			phProduct.setProductForm(1);
		}
		if (typeId ==RoleEnum.CITY_AGENT.getCode()) {// 本地商品
			phProduct.setProductType(2);
			phProduct.setProductForm(2);
		}
		// if(typeId==2){//供应商也是全国商品
		// phProduct.setProductType(1);
		// phProduct.setProductForm(1);
		// }
		// 将json转为对象、集合
		Gson gson = new Gson();
		phProduct.setCreateTime(new Date());
		phProduct.setDeleteFlag(1);// 未删除
		phProduct.setAuditState(1);// 未审核
		List<PhProductImage> imageList = gson.fromJson(imageJSON, new TypeToken<List<PhProductImage>>() {
		}.getType());
		List<PhProductPropertyVal> ppvList = gson.fromJson(productPropertyValJSON,
				new TypeToken<List<PhProductPropertyVal>>() {
				}.getType());
		phProduct.setCreateTime(new Date());
		// 后台数据验证开始
		List<String> errorList = phProduct.validateForm();
		if (errorList != null) {
			logger.info(
					"信息检索表[com.ph.shopping.facade.product.entity.PhProduct]实体中出错验证错误：错误信息如下" + gson.toJson(errorList));
			return getResult(ResultEnum.ENTITY_CHECK_EXCEPTION);
		}
		for (PhProductImage phProductImage : imageList) {
			List<String> errorList1 = phProductImage.validateForm();
			if (errorList1 != null) {
				logger.info("信息检索表[com.ph.shopping.facade.product.entity.PhProductImage]实体中出错验证错误：错误信息如下"
						+ gson.toJson(errorList1));
				return getResult(ResultEnum.ENTITY_CHECK_EXCEPTION);
			}

		}
		for (PhProductPropertyVal phProductPropertyVal : ppvList) {
			List<String> errorList2 = phProductPropertyVal.validateForm();
			if (errorList2 != null) {
				logger.info("信息检索表[com.ph.shopping.facade.product.entity.PhProductPropertyVal]实体中出错验证错误：错误信息如下"
						+ gson.toJson(errorList2));
				return getResult(ResultEnum.ENTITY_CHECK_EXCEPTION);
			}

		}

		// 添加开始
		try {
			this.iProductService.addProduct(phProduct, imageList, ppvList);
		} catch (Exception e) {
			// e.printStackTrace();
			return getResult(ResultEnum.ADD_PRODUCT_EXCEPTION);
		}
		logger.info("商品添加成功");
		return getResult(ResultEnum.SUCCESS);
	}

	/**
	 * 修改商品接口
	 *
	 * @param phProduct
	 *            商品实体, productPropertyValJSON
	 * @return result
	 * @author 李超
	 * @throws JsonProcessingException
	 *
	 * @Time 2017年3月14日
	 *
	 */
	@ResponseBody
	@RequestMapping(value = "/updateProduct", method = RequestMethod.POST)
	public Result updateProduct(@ModelAttribute PhProduct phProduct, @RequestParam String content,
			@RequestParam String imageJSON, @RequestParam String productPropertyValJSON, HttpServletRequest request)
					throws JsonProcessingException {
		logger.debug("-------------------------------获取前台商品数据-------------------------------");
		logger.debug("phProduct: " + new ObjectMapper().writeValueAsString(phProduct));
		logger.debug("imageList: " + imageJSON);
		logger.debug("pvList: " + productPropertyValJSON);
		logger.debug("-------------------------------获取前台商品数据-------------------------------");

		phProduct.setDescription(content);
		Gson gson = new Gson();
		// 后台数据验证开始
		List<String> errorList = phProduct.validateForm();
		if (errorList != null) {
			logger.info(
					"信息检索表[com.ph.shopping.facade.product.entity.PhProduct]实体中出错验证错误：错误信息如下" + gson.toJson(errorList));
			return getResult(ResultEnum.ENTITY_CHECK_EXCEPTION);
		}
		// 获取当前用户
		SessionUserVo info = getLoginUser(request);
		phProduct.setUpdateUser(info.getId());
		// phProduct.setUpdateUser(1L);
		phProduct.setUpdateTime(new Date());

		List<PhProductImage> imageList = gson.fromJson(imageJSON, new TypeToken<List<PhProductImage>>() {
		}.getType());
		for (PhProductImage phProductImage : imageList) {
			List<String> errorList1 = phProductImage.validateForm();
			if (errorList1 != null) {
				logger.info("信息检索表[com.ph.shopping.facade.product.entity.PhProductImage]实体中出错验证错误：错误信息如下"
						+ gson.toJson(errorList1));
				return getResult(ResultEnum.ENTITY_CHECK_EXCEPTION);
			}
			phProductImage.setCreateTime(new Date());
			phProductImage.setProductId(phProduct.getId());
		}

		List<PhProductPropertyVal> pvList = gson.fromJson(productPropertyValJSON,
				new TypeToken<List<PhProductPropertyVal>>() {
				}.getType());
		for (PhProductPropertyVal phProductPropertyVal : pvList) {
			List<String> errorList2 = phProductPropertyVal.validateForm();
			if (errorList2 != null) {
				logger.info("信息检索表[com.ph.shopping.facade.product.entity.PhProductPropertyVal]实体中出错验证错误：错误信息如下"
						+ gson.toJson(errorList2));
				return getResult(ResultEnum.ENTITY_CHECK_EXCEPTION);
			}
			phProductPropertyVal.setProductId(phProduct.getId());
		}

		logger.debug("-------------------------------修改商品组装数据结束-------------------------------");
		logger.debug("phProduct: " + new ObjectMapper().writeValueAsString(phProduct));
		logger.debug("imageList: " + new ObjectMapper().writeValueAsString(imageList));
		logger.debug("pvList: " + new ObjectMapper().writeValueAsString(pvList));
		logger.debug("-------------------------------修改商品组装数据结束-------------------------------");
		try {
			return iProductService.updateProduct(phProduct, imageList, pvList);
		} catch (Exception ex) {
			logger.error("修改商品异常, ex={}", ex);
			return getResult(ResultEnum.UPDATE_PRODUCT_EXCEPTION);
		}
	}

	/**
	 * 到商品修改页面 根据商品id获取商品详细信息 用于修改
	 * 
	 * @param phProductVo
	 * @return
	 *
	 * @author 李超
	 *
	 * @Time 2017年3月15日
	 *
	 */
	@RequestMapping(value = "/toUpdateProduct", method = RequestMethod.GET)
	public String toUpdateProduct(@ModelAttribute PhProductVo phProductVo, Model model,HttpServletRequest request) {
		try {
			SessionUserVo info = getLoginUser(request);
			SessionRoleVo role=info.getSessionRoleVo().get(0);
			// 商品对象
			List<PhProductVo> list = iProductService.getProductVoDetail(phProductVo);
			PhProductVo phProduct = list.get(0);
			// 金额转换
			// phProduct.setReferencePrice(MoneyTransUtil.transDivis(phProduct.getReferencePrice()
			// == null ? new BigDecimal("0") :
			// phProduct.getReferencePrice()));//市场参考价
			// phProduct.setRetailPrice(MoneyTransUtil.transDivis(phProduct.getRetailPrice()
			// == null ? new BigDecimal("0") :
			// phProduct.getRetailPrice()));//零售价
			// phProduct.setPurchasePrice(MoneyTransUtil.transDivis(phProduct.getPurchasePrice()
			// == null ? new BigDecimal("0") :
			// phProduct.getPurchasePrice()));//进货价
			// phProduct.setSettlementPrice(MoneyTransUtil.transDivis(phProduct.getSettlementPrice()
			// == null ? new BigDecimal("0") :
			// phProduct.getSettlementPrice()));//结算价
			// phProduct.setPromotionPrice(MoneyTransUtil.transDivis(phProduct.getPromotionPrice()
			// == null ? new BigDecimal("0") :
			// phProduct.getPromotionPrice()));//促销价
			// phProduct.setFreight(MoneyTransUtil.transDivis(phProduct.getFreight()
			// == null ? new BigDecimal("0") : phProduct.getFreight()));//物流费

			logger.debug("待修改商品数据: " + new ObjectMapper().writeValueAsString(phProduct));
			model.addAttribute("phProductVo", phProduct);
			// 供应商
			Supplier supplier = new Supplier();
			if(role.getRoleCode().equals(RoleEnum.ADMIN.getCode())){
				supplier.setSupplierType(CommonConstants.SUPPLIER_TYPE_TOTAL);
			}
				
			if(role.getRoleCode().equals(RoleEnum.CITY_AGENT.getCode())){
				supplier.setCreateId(info.getId());
			}
			supplier.setStatus(1);
			List<SupplierVo> supplierList = iSupplierService.getSupplierVoList(supplier);
			logger.debug("供应商列表: " + supplierList);
			model.addAttribute("supplierList", supplierList);

			// 商品分类 (肯定是3级分类)
			Long productClassifyId = phProduct.getProductClassifyId();// 自己id
			// 查出自己的对象
			PhProductClassifyVo pcvFind = new PhProductClassifyVo();
			pcvFind.setId(productClassifyId);
			PhProductClassifyVo pcv = iPhProductClassifyService.getProductClassifyVo(pcvFind);
			logger.debug("商品分类查出自己的对象数据: " + new ObjectMapper().writeValueAsString(pcv));

			// 查自己的兄弟
			PhProductClassifyVo pcvbroFind = new PhProductClassifyVo();
			pcvbroFind.setParentId(pcv.getParentId());
			pcvbroFind.setDeleteFlag(1);
			List<PhProductClassifyVo> pcL3List = iPhProductClassifyService.getProductClassifyVoList(pcvbroFind);
			logger.debug("商品分类查自己的兄弟对象s数据: " + new ObjectMapper().writeValueAsString(pcL3List));
			model.addAttribute("pcL3List", pcL3List);

			// 查直接上级对象
			PhProductClassifyVo pcvParentFind = new PhProductClassifyVo();
			pcvParentFind.setId(pcv.getParentId());
			PhProductClassifyVo pcvParent = iPhProductClassifyService.getProductClassifyVo(pcvParentFind);
			logger.debug("商品分类查直接上级对象数据: " + new ObjectMapper().writeValueAsString(pcvParent));
			model.addAttribute("pcvParent", pcvParent);

			// 查上级兄弟
			PhProductClassifyVo pcvParentbroFind = new PhProductClassifyVo();
			pcvParentbroFind.setParentId(pcvParent.getParentId());
			pcvParentbroFind.setDeleteFlag(1);
			List<PhProductClassifyVo> pcL2List = iPhProductClassifyService.getProductClassifyVoList(pcvParentbroFind);
			logger.debug("商品分类查上级兄弟对象s数据: " + new ObjectMapper().writeValueAsString(pcL2List));
			model.addAttribute("pcL2List", pcL2List);

			// 查直接一级对象
			PhProductClassifyVo pcvP1Find = new PhProductClassifyVo();
			pcvP1Find.setId(pcvParent.getParentId());
			PhProductClassifyVo pcvP1 = iPhProductClassifyService.getProductClassifyVo(pcvP1Find);
			logger.debug("商品分类查直接一级对象数据: " + new ObjectMapper().writeValueAsString(pcvP1));
			model.addAttribute("pcvP1", pcvP1);

			// 所有一级
			PhProductClassifyVo pcL1 = new PhProductClassifyVo();
			pcL1.setClassifyLevel(1);
			pcL1.setDeleteFlag(1);
			List<PhProductClassifyVo> pcL1List = iPhProductClassifyService.getProductClassifyVoList(pcL1);
			logger.debug("商品分类查所有一级对象s数据: " + new ObjectMapper().writeValueAsString(pcL1List));
			model.addAttribute("pcL1List", pcL1List);

			return "/product/products/update";
		} catch (Exception ex) {
			logger.error("获取商品信息异常, ex={}", ex);
			return "";
		}
	}

	/**
	 * 商品查看单条/多条详情记录查询
	 * 
	 * @author hewl
	 * @param phProductVo
	 * @return Result
	 */
	@RequestMapping(value = "/getProductDetail", method = RequestMethod.GET)
	public @ResponseBody Result getProductDetail(PhProductVo phProductVo) throws Exception {
		Result result = new Result();
		result.setData(iProductService.getProductVoDetail(phProductVo));
		return result;
	}

	/**
	 * 商品列表查询页面跳转
	 * 
	 * @author hewl
	 * @return String
	 * @throws Exception
	 */
	@RequestMapping(value = "/listPage")
	public String listPage(Model model, String supplierId, HttpServletRequest request) throws Exception {
		//model.addAttribute("supplierId", supplierId);// 接口那边需要的id
		// model.addAttribute("auditState", "3");//接口那边需要的id
		SessionUserVo info = getLoginUser(request);
		SessionRoleVo role = info.getSessionRoleVo().get(0);
		if(StringUtils.isNotEmpty(supplierId)){//其他地方调用的时候
			model.addAttribute("supplierId", supplierId);// 接口那边需要的id
		}else{
			if (role.getRoleCode() == RoleEnum.ADMIN.getCode()) {
				model.addAttribute("createUser", "");
			}else if(role.getRoleCode() == RoleEnum.SUPPLIER.getCode()){
				model.addAttribute("supplierId",info.getId());
			}else{
				model.addAttribute("createUser", info.getId());
			}
			
		}
		

		return "product/list/productList";
	}

	/**
	 * 商品审核列表查询页面跳转
	 * 
	 * @author hewl
	 * @return String
	 * @throws Exception
	 */
	@RequestMapping(value = "/auditListPage")
	public String auditListPage(Model model,HttpServletRequest request) throws Exception {
		model.addAttribute("auditState", "1,2");// 接口那边需要的id
		SessionUserVo info = getLoginUser(request);
		SessionRoleVo role = info.getSessionRoleVo().get(0);
		if (role.getRoleCode() == RoleEnum.ADMIN.getCode()) {
			model.addAttribute("createUser", "");
		} else if (role.getRoleCode() == RoleEnum.CITY_AGENT.getCode()){
			model.addAttribute("createUser", info.getId());
		}else{
			model.addAttribute("createUser", "");
		}
		return "product/list/audit/productAuditList";
	}

	/**
	 * 商品已上架列表查询页面跳转
	 * 
	 * @author hewl
	 * @return String
	 * @throws Exception
	 */
	@RequestMapping(value = "/saleNoSaleListPage")
	public String saleNoSaleListPage(Model model,HttpServletRequest request) throws Exception {
		SessionUserVo info = getLoginUser(request);
		SessionRoleVo role = info.getSessionRoleVo().get(0);
		model.addAttribute("saleNoSaleStatus", "1");// 接口那边需要的id
		if (role.getRoleCode() == RoleEnum.ADMIN.getCode()) {
			model.addAttribute("createUser", "");
		} else if (role.getRoleCode() == RoleEnum.CITY_AGENT.getCode()){
			model.addAttribute("createUser", info.getId());
		}else{
			model.addAttribute("createUser", "");
		}
		return "product/list/saleNo/productSaleNoSaleList";
	}

	/**
	 * 商品列表查询
	 * 
	 * @author hewl
	 * @param phProductVo
	 * @return Result
	 */
	@RequestMapping(value = "/getProductPageList", method = RequestMethod.GET)
	public @ResponseBody Object getProductPageList(PageBean pageBean, PhProductVo phProductVo) throws Exception {
		phProductVo.setDeleteFlag(1);
		if (StringUtils.isNotEmpty(phProductVo.getAuditStateExtends())) {
			phProductVo.setAuditStateExtendsList(Arrays.asList(phProductVo.getAuditStateExtends().split(",")));
		}
		return iProductService.getProductVoPageList(pageBean, phProductVo);
	}

	/**
	 * 逻辑删除商品
	 * 
	 * @author hewl
	 * @param phProductVo:id
	 * @return Result
	 */
	@RequestMapping(value = "/deletePhProduct", method = RequestMethod.GET)
	public @ResponseBody Result deletePhProduct(PhProductVo phProductVo) throws Exception {
		Result result = new Result();
		if (StringUtils.isNotEmpty(phProductVo.getCustorId())) {
			phProductVo.setAuditStateExtendsList(Arrays.asList(phProductVo.getCustorId().split(",")));
			result = iProductService.deleteLogicPhProduct(phProductVo);
		}
		return result;
	}

	/**
	 * 审核商品
	 * 
	 * @author hewl
	 * @param phProductVo:id-auditState
	 * @return Result
	 */
	@RequestMapping(value = "/auditPhProduct", method = RequestMethod.GET)
	public @ResponseBody Result auditPhProduct(PhProductVo phProductVo) throws Exception {
		return iProductService.auditPhProduct(phProductVo);
	}

	/**
	 * 商品上架、下架
	 * 
	 * @author hewl
	 * @param phProductVo:id-saleNoSaleStatus
	 * @return Result
	 */
	@RequestMapping(value = "/onsalPhProduct", method = RequestMethod.GET)
	public @ResponseBody Result onsalPhProduct(PhProductVo phProductVo) throws Exception {
		return iProductService.onsalPhProduct(phProductVo);
	}

	/**
	 * 查看商品详情方法
	 * 
	 * @param phProductVo
	 * @param model
	 * @author yyg
	 */
	@RequestMapping(value = "/toSeeProductDetails", method = RequestMethod.GET)
	public String toSeeProductDetails(@ModelAttribute PhProductVo phProductVo, Model model) {
		try {
			// 商品对象
			List<PhProductVo> list = iProductService.getProductVoDetail(phProductVo);
			PhProductVo phProduct = list.get(0);
			model.addAttribute("phProductVo", phProduct);
			// 供应商
			Supplier supplier = new Supplier();
			supplier.setStatus(1);
			List<SupplierVo> supplierList = iSupplierService.getSupplierVoList(supplier);
			logger.debug("供应商列表: " + supplierList);
			model.addAttribute("supplierList", supplierList);

			// 商品分类 (肯定是3级分类)
			Long productClassifyId = phProduct.getProductClassifyId();// 自己id
			// 查出自己的对象
			PhProductClassifyVo pcvFind = new PhProductClassifyVo();
			pcvFind.setId(productClassifyId);
			PhProductClassifyVo pcv = iPhProductClassifyService.getProductClassifyVo(pcvFind);
			logger.debug("商品分类查出自己的对象数据: " + new ObjectMapper().writeValueAsString(pcv));

			// 查自己的兄弟
			PhProductClassifyVo pcvbroFind = new PhProductClassifyVo();
			pcvbroFind.setParentId(pcv.getParentId());
			pcvbroFind.setDeleteFlag(1);
			List<PhProductClassifyVo> pcL3List = iPhProductClassifyService.getProductClassifyVoList(pcvbroFind);
			logger.debug("商品分类查自己的兄弟对象s数据: " + new ObjectMapper().writeValueAsString(pcL3List));
			model.addAttribute("pcL3List", pcL3List);

			// 查直接上级对象
			PhProductClassifyVo pcvParentFind = new PhProductClassifyVo();
			pcvParentFind.setId(pcv.getParentId());
			PhProductClassifyVo pcvParent = iPhProductClassifyService.getProductClassifyVo(pcvParentFind);
			logger.debug("商品分类查直接上级对象数据: " + new ObjectMapper().writeValueAsString(pcvParent));
			model.addAttribute("pcvParent", pcvParent);

			// 查上级兄弟
			PhProductClassifyVo pcvParentbroFind = new PhProductClassifyVo();
			pcvParentbroFind.setParentId(pcvParent.getParentId());
			pcvParentbroFind.setDeleteFlag(1);
			List<PhProductClassifyVo> pcL2List = iPhProductClassifyService.getProductClassifyVoList(pcvParentbroFind);
			logger.debug("商品分类查上级兄弟对象s数据: " + new ObjectMapper().writeValueAsString(pcL2List));
			model.addAttribute("pcL2List", pcL2List);

			// 查直接一级对象
			PhProductClassifyVo pcvP1Find = new PhProductClassifyVo();
			pcvP1Find.setId(pcvParent.getParentId());
			PhProductClassifyVo pcvP1 = iPhProductClassifyService.getProductClassifyVo(pcvP1Find);
			logger.debug("商品分类查直接一级对象数据: " + new ObjectMapper().writeValueAsString(pcvP1));
			model.addAttribute("pcvP1", pcvP1);

			// 所有一级
			PhProductClassifyVo pcL1 = new PhProductClassifyVo();
			pcL1.setClassifyLevel(1);
			pcL1.setDeleteFlag(1);
			List<PhProductClassifyVo> pcL1List = iPhProductClassifyService.getProductClassifyVoList(pcL1);
			logger.debug("商品分类查所有一级对象s数据: " + new ObjectMapper().writeValueAsString(pcL1List));
			model.addAttribute("pcL1List", pcL1List);

			return "/product/products/detail";
		} catch (Exception ex) {
			logger.error("获取商品信息异常, ex={}", ex);
			return "";
		}
	}

}
